package lanxing.future.path;

/**
 * @author <a href="mailto:lanxing@chances.com.cn">lanxing</a>
 * @version 2019年2月27日
 *
 */
import java.io.File;

public class UserFileSystem {

    public static String getHashPath(String code) {
        return getHashPath(code, '/');
    }

    public static String getHashPath(String code, char split) {
        StringBuffer buffer = new StringBuffer();
        double level = Math.log(2147483647.0D) / Math.log(256.0D);
        int nLevel = (int) Math.round(level);
        int h = code.hashCode();
        for (long i = nLevel; i > 0L; i -= 1L) {
            buffer.append(h & 0xFF).append(split);
            h >>= 8;
        }
        return buffer.toString();
    }

    public static String getHashPath(int hashCode) {
        StringBuffer buffer = new StringBuffer();
        double level = Math.log(2147483647.0D) / Math.log(256.0D);
        int nLevel = (int) Math.round(level);
        int h = hashCode;
        for (long i = nLevel; i > 0L; i -= 1L) {
            buffer.append(h & 0xFF).append(File.separator);
            h >>= 8;
        }
        return buffer.toString();
    }

    protected String getClientPath(String name) {
        return getHashPath(name.hashCode());
    }
    
    public static void main(String[] args) {
        String userId = "001";
        int i = 10;
        while(i>0) {
            System.out.println(UserFileSystem.getHashPath(userId));
            i--;
        }
    } 

}